#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc2_r12_aux_ch4_cbs1.info <<'%EOF%'
   cc2_r12_aux_ch4_cbs1
   -----------
   Molecule:         Methane (CH4)
   Wave Function:    CC2-R12,CCSD(R12) / 6-311G**
   Test Purpose:     Check CABS for CC-R12 / Ansatz 1 
%EOF%

#######################################################################
#  MOLECULE INPUT
#######################################################################
cat > cc2_r12_aux_ch4_cbs1.mol <<'%EOF%'
# > BASIS                                                                       
# > 6-311G** 6-311++G(3df,3pd)                                                  
INTGRL
CH4: CC-R12/Ansatz1 excitation energies using symmetry                         
                                                                                
    4  0 2 XY XZ      0.10D-14
 1      6.    1    3    1    1    1
C        0.0000000000000     0.0000000000000     0.0000000000000
H  11    4
     4563.2400000000        0.0019666500        0.0000000000        0.0000000000
                            0.0000000000
      682.0240000000        0.0152306000        0.0000000000        0.0000000000
                            0.0000000000
      154.9730000000        0.0761269000        0.0000000000        0.0000000000
                            0.0000000000
       44.4553000000        0.2608010000        0.0000000000        0.0000000000
                            0.0000000000
       13.0290000000        0.6164620000        0.0000000000        0.0000000000
                            0.0000000000
        1.8277300000        0.2210060000        0.0000000000        0.0000000000
                            0.0000000000
       20.9642000000        0.0000000000        0.1146600000        0.0000000000
                            0.0000000000
        4.8033100000        0.0000000000        0.9199990000        0.0000000000
                            0.0000000000
        1.4593300000        0.0000000000       -0.0030306800        0.0000000000
                            0.0000000000
        0.4834560000        0.0000000000        0.0000000000        1.0000000000
                            0.0000000000
        0.1455850000        0.0000000000        0.0000000000        0.0000000000
                            1.0000000000
H   5    3
       20.9642000000        0.0402487000        0.0000000000        0.0000000000
        4.8033100000        0.2375940000        0.0000000000        0.0000000000
        1.4593300000        0.8158540000        0.0000000000        0.0000000000
        0.4834560000        0.0000000000        1.0000000000        0.0000000000
        0.1455850000        0.0000000000        0.0000000000        1.0000000000
H   1    1
        0.6260000000        1.0000000000
 1      1.    1    2    1    1
H        1.2767310000000     1.2767310000000     1.2767310000000
H   5    3
       33.8650000000        0.0254938000        0.0000000000        0.0000000000
        5.0947900000        0.1903730000        0.0000000000        0.0000000000
        1.1587900000        0.8521610000        0.0000000000        0.0000000000
        0.3258400000        0.0000000000        1.0000000000        0.0000000000
        0.1027410000        0.0000000000        0.0000000000        1.0000000000
H   1    1
        0.7500000000        1.0000000000
 2      0.    1    4    1    1    1    1
C        0.0000000000000     0.0000000000000     0.0000000000000
H   1    0
        0.0438000000
H   1    0
        0.0438000000
H   2    0
        2.5040000000
        0.1565000000
H   1    0
        0.8000000000
 2      0.    1    3    1    1    1
H        1.2767310000000     1.2767310000000     1.2767310000000
H   1    0
        0.0360000000
H   2    0
        3.0000000000
        0.1875000000
H   1    0
        1.0000000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc2_r12_aux_ch4_cbs1.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTION
*MOLBAS
.R12AUX
**INTEGRALS
.R12
**WAVE FUNCTION
.CC
*ORBITAL INPUT
.MOSTART
 H1DIAG
.R12ORB
 1 1 1 1
*SCF IN
.THRESH
 1.0D-10
*CC INPUT
.CC2
.CCSD
.PRINT
 5
.FREEZE
 1 0
.THRENR
 1.0D-10
.THRLEQ
 1.0D-08
.MAX IT
 100
*CCEXCI
.THREXC
 1.0D-08
.NCCEXCI
 3 3 3 3 
*R12 INPUT
.NO HYB
.CC2
 1B
.NATVIR
.CABS
**END OF DALTON INPUT
%EOF%

#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc2_r12_aux_ch4_cbs1.check
cat >>cc2_r12_aux_ch4_cbs1.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi   

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#           Total SCF   energy:                   -40.1917720926
#           Total MP2-R12/B energy:               -40.3873962174
#           Total CC2-R12/B energy:               -40.3886100200
#
#+=============================================================================+
#|  sym. | Exci.  |        CC2-R12/B  Excitation energies            | ||T1||  |
#|(spin, |        +------------------------------------------------------------+
#| spat) |        |     Hartree    |       eV.      |     cm-1       |    %    |
#+=============================================================================+
#| ^1A   |    1   |     0.4873526  |      13.26154  |    106961.542  |  97.36  |
#| ^1A   |    2   |     0.4873526  |      13.26154  |    106961.542  |  97.37  |
#| ^1A   |    3   |     0.5386058  |      14.65621  |    118210.308  |  97.14  |
#+-----------------------------------------------------------------------------+
#| ^1B2  |    1   |     0.4136515  |      11.25603  |     90786.017  |  97.05  |
#| ^1B2  |    2   |     0.4784300  |      13.01874  |    105003.244  |  97.01  |
#| ^1B2  |    3   |     0.4873904  |      13.26257  |    106969.831  |  97.18  |
#+-----------------------------------------------------------------------------+
#| ^1B1  |    1   |     0.4136515  |      11.25603  |     90786.017  |  97.05  |
#| ^1B1  |    2   |     0.4784300  |      13.01874  |    105003.244  |  97.01  |
#| ^1B1  |    3   |     0.4873904  |      13.26257  |    106969.831  |  97.18  |
#+-----------------------------------------------------------------------------+
#| ^1B3  |    1   |     0.4136515  |      11.25603  |     90786.017  |  97.05  |
#| ^1B3  |    2   |     0.4784300  |      13.01874  |    105003.244  |  97.01  |
#| ^1B3  |    3   |     0.4873904  |      13.26257  |    106969.831  |  97.18  |
#+=============================================================================+
#
#           Total SCF   energy:                   -40.1917720926
#           Total RSTAR(R12)/B energy:            -40.3886100200
#           Total CCSD(R12)/B energy:             -40.4034406713
#
#+=============================================================================+
#|  sym. | Exci.  |        CCSD(R12)/ Excitation energies            | ||T1||  |
#|(spin, |        +------------------------------------------------------------+
#| spat) |        |     Hartree    |       eV.      |     cm-1       |    %    |
#+=============================================================================+
#| ^1A   |    1   |     0.4825182  |      13.12999  |    105900.497  |  95.82  |
#| ^1A   |    2   |     0.4825182  |      13.12999  |    105900.497  |  95.83  |
#| ^1A   |    3   |     0.5380974  |      14.64237  |    118098.718  |  96.12  |
#+-----------------------------------------------------------------------------+
#| ^1B2  |    1   |     0.4104396  |      11.16863  |     90081.079  |  95.70  |
#| ^1B2  |    2   |     0.4723962  |      12.85456  |    103678.990  |  95.00  |
#| ^1B2  |    3   |     0.4844071  |      13.18139  |    106315.063  |  95.95  |
#+-----------------------------------------------------------------------------+
#| ^1B1  |    1   |     0.4104396  |      11.16863  |     90081.079  |  95.70  |
#| ^1B1  |    2   |     0.4723962  |      12.85456  |    103678.990  |  95.00  |
#| ^1B1  |    3   |     0.4844071  |      13.18139  |    106315.063  |  95.95  |
#+-----------------------------------------------------------------------------+
#| ^1B3  |    1   |     0.4104396  |      11.16863  |     90081.079  |  95.70  |
#| ^1B3  |    2   |     0.4723962  |      12.85456  |    103678.990  |  95.00  |
#| ^1B3  |    3   |     0.4844071  |      13.18139  |    106315.063  |  95.95  |
#+=============================================================================+
#
#
CRIT1=`$GREP "Total MP2-R12/B energy: *\-40\.387396217" $log | wc -l`
TEST[1]=`expr	$CRIT1`
CTRL[1]=2
ERROR[1]="MP2-R12/B ENERGY NOT CORRECT"
CRIT2=`$GREP "Total CC2-R12/B energy: *\-40\.388610020" $log | wc -l`
TEST[2]=`expr	$CRIT1`
CTRL[2]=2
ERROR[2]="CC2-R12/B ENERGY NOT CORRECT"
CRIT3=`$GREP "\^1A .* 13\.26154" $log | wc -l`
CRIT4=`$GREP "\^1A .* 14\.65621" $log | wc -l` 
TEST[3]=`expr   $CRIT3 \+ $CRIT4`
CTRL[3]=3
ERROR[3]="CC2-R12 Sym. A EXCITATION ENERGIES NOT CORRECT"
CRIT5=`$GREP "\^1B[123] .* 11\.25603" $log | wc -l`
CRIT6=`$GREP "\^1B[123] .* 13\.01874" $log | wc -l`
CRIT7=`$GREP "\^1B[123] .* 13\.26257" $log | wc -l`
TEST[4]=`expr   $CRIT5 \+ $CRIT6 \+ $CRIT7`
CTRL[4]=9
ERROR[4]="CC2-R12 Sym. B EXCITATION ENERGIES NOT CORRECT"
CRIT8=`$GREP "Total CCSD\(R12\)/B energy: *\-40\.4034406713" $log | wc -l`
TEST[5]=`expr   $CRIT8`
CTRL[5]=2
ERROR[5]="CCSD(R12)/B ENERGY NOT CORRECT"
CRIT9=`$GREP "\^1A .* 13\.12999" $log | wc -l`
CRIT10=`$GREP "\^1A .* 14\.64237" $log | wc -l`
TEST[6]=`expr   $CRIT9 \+ $CRIT10`
CTRL[6]=3
ERROR[6]="CCSD(R12) Sym. A EXCITATION ENERGIES NOT CORRECT"
CRIT11=`$GREP "\^1B[123] .* 11\.16863" $log | wc -l`
CRIT12=`$GREP "\^1B[123] .* 12\.85456" $log | wc -l`
CRIT13=`$GREP "\^1B[123] .* 13\.18139" $log | wc -l`
TEST[7]=`expr   $CRIT5 \+ $CRIT6 \+ $CRIT7`
CTRL[7]=9
ERROR[7]="CCSD(R12) Sym. B EXCITATION ENERGIES NOT CORRECT"

PASSED=1
for i in 1 2 3 4 5 6 7
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
